
var ___localStackid = 0;


function buildLogDataCell(msg, args){

	var result = {};

	result.id = ++___localStackid;
	result.date = new Date();
	result.time = result.date.getHours() + ":" + result.date.getMinutes() + ":" + result.date.getSeconds();
	result.args = args;
	result.msg = msg;

	result.stack = "";

    var Exception = Java.use("java.lang.Exception");
    var ins = Exception.$new("Exception");
    var straces = ins.getStackTrace();
	do{
		if (undefined == straces || null == straces) {
			break;
		}
		for (var i = 0; i < straces.length; i++) {
			var str = "   " + straces[i].toString();
			result.stack += str + "\r\n";
		}
	}while(false);

    Exception.$dispose();

	return result;
}


function displayLogDataCell(logDataCell){

	console.log("\r\n[# " + logDataCell.id + "]===========start===========");

	console.log("\r\n[# " + logDataCell.id + "][" + logDataCell.time + "]" + logDataCell.msg);
	for(var i = 0; i < logDataCell.args.length; i++){
		try{
			console.log("\r\n[# " + logDataCell.id + "]\targs " + (i + 1) + ": " + logDataCell.args[i].toString());
		}catch(e){
			console.log("\r\n[# " + logDataCell.id + "]\targs " + (i + 1) + ": " + logDataCell.args[i]);
		}
	}

	console.log("\r\n[# " + logDataCell.id + "]\tstack:\r\n" + logDataCell.stack);

	console.log("\r\n[# " + logDataCell.id + "]===========end===========");

}



Java.perform(function() {
	var class_name = Java.use("java.lang.Thread");
	class_name.$init.overload().implementation = function () {

		displayLogDataCell(buildLogDataCell("java.lang.Thread $new", []));

		var temp = this.$init();
		return temp;

	};


	class_name.$init.overload("java.lang.Runnable").implementation = function (arg1) {

		displayLogDataCell(buildLogDataCell("java.lang.Thread $new with java.lang.Runnable", [arg1]));

		var temp = this.$init(arg1);
		return temp;

	};

	class_name.$init.overload("java.lang.Runnable", "java.lang.String").implementation = function (arg1, arg2) {

		displayLogDataCell(buildLogDataCell("java.lang.Thread $new with java.lang.Runnable and java.lang.String", [arg1, arg2]));

		var temp = this.$init(arg1, arg2);
		return temp;

	};


	class_name.$init.overload("java.lang.String").implementation = function (arg1) {

		displayLogDataCell(buildLogDataCell("java.lang.Thread $new with java.lang.String", [arg1]));

		var temp = this.$init(arg1);
		return temp;

	};


	class_name.$init.overload("java.lang.ThreadGroup", "java.lang.Runnable").implementation = function (arg1, arg2) {

		displayLogDataCell(buildLogDataCell("java.lang.Thread $new with java.lang.ThreadGroup and java.lang.Runnable", [arg1, arg2]));

		var temp = this.$init(arg1, arg2);
		return temp;

	};

	class_name.$init.overload("java.lang.ThreadGroup", "java.lang.Runnable", "java.lang.String").implementation = function (arg1, arg2, arg3) {

		displayLogDataCell(buildLogDataCell("java.lang.Thread $new with java.lang.ThreadGroup and java.lang.Runnable and java.lang.String", [arg1, arg2, arg3]));

		var temp = this.$init(arg1, arg2, arg3);
		return temp;

	};


	//有问题
	class_name.$init.overload("java.lang.ThreadGroup", "java.lang.Runnable", "java.lang.String", "long").implementation = function (arg1, arg2, arg3, arg4) {

		displayLogDataCell(buildLogDataCell("java.lang.Thread $new with java.lang.ThreadGroup and java.lang.Runnable and java.lang.String and long", [arg1, arg2, arg3, arg4]));

		var temp = this.$init(arg1, arg2, arg3, arg4);
		return temp;

	};

	class_name.$init.overload("java.lang.ThreadGroup", "java.lang.String").implementation = function (arg1, arg2) {

		displayLogDataCell(buildLogDataCell("java.lang.Thread $new with java.lang.ThreadGroup and java.lang.String", [arg1, arg2]));

		var temp = this.$init(arg1, arg2);
		return temp;

	};


});

